<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>User_List</title>
</head>
<body>
	<div>
		<table>
			<tbody>
				<div style="height:25px;background:cornflowerblue;">
					<input type="button" value="用户添加" style="float:right;" onclick="window.open('${pageContext.request.contextPath}/user_to_add','mainFrame')"/>
				</div>
				<tr>
					<td>编号</td>
					<td>用户名</td>
					<td>角色</td>
					<td>持有人</td>
					<td>操作</td>
				</tr>
				<c:forEach var="user" items="${sessionScope.user_list }" varStatus="index">
					<tr>
						<td>${user.userId }</td>
						<td>${user.username }</td>
						<td>${user.tblRoles.roleName }</td>
						<td>${user.tblPersonalInformation.fullName }</td>
						<td>
							<button onclick="javascript:window.location.href='${pageContext.request.contextPath}/user_detail?userId=${user.userId}'">编辑</button>
							<button onclick="user_delete('${user.userId}');">删除</button>
						</td>
						<td id="message" style="color:red;"></td>
					</tr>
				</c:forEach>
			</tbody>
		</table>
	</div>	
</body>
<script src="${pageContext.request.contextPath }/js/jquery-1.11.0.js" type="text/javascript"></script>
<script type="text/javascript" >
	function user_delete(userId){
		var flag = confirm("是否删除该条记录？");
		if(flag){
			$.ajax({
				type:'post',
				url:'user_delete',
				data:'userId='+userId,
				success:function(){
					window.location.href='tolist';
					document.getElementById("message").innerHTML='删除成功！';
					document.getElementById("message").style.color = 'green';
				},
				error:function(XMLHttpRequest, textStatus, errorThrown){
					document.getElementById("message").innerHTML='删除失败！';
					document.getElementById("message").style.color = 'red';
				}
			});
		}else{
			alert('请谨慎选择');
		}
	}
</script>
</html>